import java.util.ArrayList;
import java.util.Observable;

public class HatchToTable extends Observable implements Runnable
{
	ArrayList<FoodOrder> bt1 = new ArrayList<FoodOrder>();
	ArrayList<FoodOrder> bt2 = new ArrayList<FoodOrder>();
	ArrayList<FoodOrder> gt1 = new ArrayList<FoodOrder>();
	ArrayList<FoodOrder> gt2 = new ArrayList<FoodOrder>();
	ArrayList<FoodOrder> rt1 = new ArrayList<FoodOrder>();
	ArrayList<FoodOrder> rt2 = new ArrayList<FoodOrder>();
	String bt1Rep = "";
	String bt2Rep = "";
	String gt1Rep = "";
	String gt2Rep = "";
	String rt1Rep = "";
	String rt2Rep = "";

	public HatchToTable()
	{	
		Thread t = new Thread(this);
		t.start();
	}

	public String getBt1() 
	{
		for(FoodOrder food : bt1)
		{
			bt1Rep += String.format("%-30s",food.getItem()) + "\t" + String.format("%-10s",food.getQuantity()) + "\n";
		}
		return bt1Rep;
	}

	public String getBt2() 
	{
		for(FoodOrder food : bt2)
		{
			bt2Rep += String.format("%-30s",food.getItem()) + "\t" + String.format("%-10s",food.getQuantity()) + "\n";
		}
		return bt2Rep;
	}

	public String getGt1() 
	{
		for(FoodOrder food : gt1)
		{
			gt1Rep += String.format("%-30s",food.getItem()) + "\t" + String.format("%-10s",food.getQuantity()) + "\n";
		}
		return gt1Rep;
	}

	public String getGt2() 
	{		
		for(FoodOrder food : gt2)
		{
			gt2Rep += String.format("%-30s",food.getItem()) + "\t" + String.format("%-10s",food.getQuantity()) + "\n";
		}
		return gt2Rep;
	}

	public String getRt1() 
	{
		for(FoodOrder food : rt1)
		{
			rt1Rep += String.format("%-30s",food.getItem()) + "\t" + String.format("%-10s",food.getQuantity()) + "\n";
		}
		return rt1Rep;
	}

	public String getRt2() 
	{ 
		for(FoodOrder food : rt2)
		{
			rt2Rep += String.format("%-30s",food.getItem()) + "\t" + String.format("%-10s",food.getQuantity()) + "\n";
		}
		return rt2Rep;
	}

	public void run()
	{
		try
		{

			Thread.sleep(500);

		}
		catch (NumberFormatException nfe) {
			String error = "Number conversion error in  - " + nfe.getMessage();
			System.out.println(error);
		}
		// this catches missing items if only one or two items
		// other omissions will result in other errors
		catch (Exception e) {
			String error = "Error  : '" + "' index position : "
					+ e.getMessage();
			System.out.println(error);
		}

	}
	public void start(FoodOrder f)
	{	
		if(f.getTableName().equals("Blue 1"))
			bt1.add(f);
		else
			if(f.getTableName().equals("Blue 2"))
				bt2.add(f);
			else
				if(f.getTableName().equals("Green 1"))
					gt1.add(f);
				else
					if(f.getTableName().equals("Green 2"))
						gt2.add(f);
					else
						if(f.getTableName().equals("Red 1"))
							rt1.add(f);
						else
							if(f.getTableName().equals("Red 2"))
								rt2.add(f);


	}
}
